{% extends 'base.html' %}

{% block content %}

    <!-- Plugins css-->
    <link href="/static/assets/plugins/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css" rel="stylesheet">
    <link href="/static/assets/plugins/bootstrap-select/dist/css/bootstrap-select.min.css" rel="stylesheet" />
    <link href="/static/assets/plugins/bootstrap-touchspin/dist/jquery.bootstrap-touchspin.min.css" rel="stylesheet" />
    <link href="/static/assets/plugins/summernote/dist/summernote.css" rel="stylesheet" />

    <div class="container">
        <!-- Page-Title -->
        <div class="row">
            <div class="col-sm-12">
                <h4 class="page-title">资产管理</h4>
                <ol class="breadcrumb">
                    <li>
                        <a href="#">资产管理</a>
                    </li>
                    <li>
                        <a href="#">资产表管理</a>
                    </li>
                    <li class="active">
                        资产修改
                    </li>
                </ol>
            </div>
        </div>

        <form class="form-horizontal" role="form">

            {% csrf_token  %}
            <!-- 基本信息 -->
            <div class="row">
                <div class="col-sm-8">
                    <div class="card-box">
                        <h4 class="m-t-0 header-title"><b>基本信息：</b></h4>
                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-md-3 control-label">资产编号</label>
                                    <div class="col-md-9">
                                        <input type="text" class="form-control" name="device_number" value="{{AssetsData.device_number}}">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">IDC</label>
                                    <div class="col-md-9">
                                        <select class="selectpicker show-tick" data-style="btn-white" name="idc">
                                            {% for idc in IdcData%}
                                                {% if AssetsData.IDC.id == idc.id %}
                                                    <option value="{{idc.id}}" selected>{{idc.idc_name}}</option>
                                                {%else%}
                                                    <option value="{{idc.id}}" >{{idc.idc_name}}</option>
                                                {%endif%}
                                            {% endfor%}
                                        </select>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-md-3 control-label">业务名</label>
                                    <div class="col-md-9">
                                        <select class="selectpicker show-tick" data-style="btn-white" name="business">
                                            {% for bus in BusinessData%}
                                                {% if AssetsData.business.id == bus.id %}
                                                    <option value="{{bus.id}}" selected>{{bus.name}}</option>
                                                {%else%}
                                                    <option value="{{bus.id}}">{{bus.name}}</option>
                                                {%endif%}
                                            {% endfor%}
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">资产状态</label>
                                    <div class="col-md-9">
                                        <select class="selectpicker show-tick" data-style="btn-white" name="status">
                                            {% for status in AssetsData.status_choice%}
                                                {% if AssetsData.status == status.0 %}
                                                    <option value="{{status.0}}" selected>{{status.1}}</option>
                                                {%else%}
                                                    <option value="{{status.0}}">{{status.1}}</option>
                                                {%endif%}
                                            {%endfor%}
                                        </select>
                                    </div>
                                </div>
                            </div>

                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-md-2 control-label">设备名</label>
                                    <div class="col-md-10">
                                        <input type="text" class="form-control" name="host_name" value="{{AssetsData.host_name}}">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-2 control-label">设备类型</label>
                                    <div class="col-md-10">
                                        <select class="selectpicker show-tick" data-style="btn-white" name="device_type">
                                            {% for type in DeviceTypeData%}
                                                {% if AssetsData.device_type.id == type.id %}
                                                    <option value="{{type.id}}" selected>{{type.name}}</option>
                                                {%else%}
                                                    <option value="{{type.id}}">{{type.name}}</option>
                                                {%endif%}
                                            {%endfor%}
                                        </select>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label">购买方式</label>
                                    <div class="col-md-10">
                                        <select class="selectpicker show-tick" data-style="btn-white" name="buy_type">
                                            {% for buy in AssetsData.buy_type_choice%}
                                                {%if AssetsData.buy_type == buy.0 %}
                                                    <option value="{{buy.0}}" selected>{{buy.1}}</option>
                                                {%else%}
                                                    <option value="{{buy.0}}">{{buy.1}}</option>
                                                {%endif%}
                                            {%endfor%}
                                        </select>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label">购买价格</label>
                                    <div class="col-md-10">
                                        <input type="text" class="form-control"  name="price" value="{{AssetsData.price}}">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 其它信息： -->
            <div class="row">
                <div class="col-sm-8">
                    <div class="card-box">
                        <h4 class="m-t-0 header-title"><b>其它信息：</b></h4>
                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-md-3 control-label">保修期</label>
                                    <div class="col-md-9">
                                        <input type="text" class="form-control" value="{{AssetsData.Warranty}}" name="Warranty">
                                    </div>
                                </div>
                             	<div class="form-group">
                                <label class="control-label col-sm-3">购买时间</label>
                                <div class="col-sm-9">
                                    <div class="input-group">
                                        <input type="text" class="form-control" placeholder="yyyy/mm/dd" value="{{AssetsData.buy_time}}" name="buytime" id="datepicker-autoclose">
                                        <span class="input-group-addon bg-custom b-0 text-white"><i class="icon-calender"></i></span>
                                    </div><!-- input-group -->
                                </div>
                            </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">使用时间范围</label>
                                    <div class="col-sm-9">
                                        <div class="input-daterange input-group" id="date-range">
                                            <input type="text" class="form-control" value="{{AssetsData.suse_time| date:'Y-m-d'}}" name="start">
                                            <span class="input-group-addon bg-custom b-0 text-white">至</span>
                                            <input type="text" class="form-control"  value="{{AssetsData.euse_time|date:'Y-m-d'}}" name="end">
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">管理员邮箱</label>
                                    <div class="col-md-9">
                                        <select class="selectpicker show-tick" data-style="btn-white" name="admin">
                                            {% for user in AdminUser%}
                                                {% if AssetsData.admin.id == user.id %}
                                                    <option value="{{user.id}}" selected>{{user}}</option>
                                                {%else%}
                                                    <option value="{{user.id}}">{{user}}</option>
                                                {%endif%}
                                            {%endfor%}
                                        </select>
                                    </div>
                                </div>


                                  <div class="form-group">
                                    <label class="col-md-3 control-label">提供商</label>
                                    <div class="col-md-9">
                                        <select class="selectpicker show-tick" data-style="btn-white" name="provider">
                                            {% for pr in ProviderData %}
                                                {% if AssetsData.provider.id == pr.id %}
                                                    <option value="{{pr.id}}" selected>{{pr}}</option>
                                                {%else%}
                                                    <option value="{{pr.id}}">{{pr}}</option>
                                                {%endif%}
                                            {%endfor%}
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 文本域 -->
            <div class="row">
                <div class="col-sm-8">
                    <div class="card-box">
                        <h4 class="m-b-30 m-t-0 header-title"><b>备注</b></h4>
                        <div class="summernote">
                            <h4></h4>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 提交按钮 -->
            <div class="row">
                <div class="col-sm-8">
                    <div class="form-group text-right">
                        <button type="submit" class="btn btn-primary" >
                            提交
                        </button>
                    </div>
                </div>
            </div>

        </form>

    </div> <!-- container -->



<script type="text/javascript" src="/static/assets/plugins/multiselect/js/jquery.multi-select.js"></script>
<script src="/static/assets/plugins/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
<script src="/static/assets/plugins/bootstrap-select/dist/js/bootstrap-select.min.js" type="text/javascript"></script>
<script src="/static/assets/plugins/summernote/dist/summernote.min.js"></script>
<script>
    jQuery(document).ready(function() {
        $('.selectpicker').selectpicker();

        // Date Picker
        jQuery('#datepicker').datepicker();
        jQuery('#datepicker-autoclose').datepicker({
            format: "yyyy-mm-dd",
            autoclose: true,
            todayHighlight: true
        });
        jQuery('#datepicker-inline').datepicker();
        jQuery('#datepicker-multiple-date').datepicker({
            format: "mm/dd/yyyy",
            clearBtn: true,
            multidate: true,
            multidateSeparator: ","
        });

        jQuery('#date-range').datepicker({
            format: "yyyy-mm-dd",
            toggleActive: true

        });

        // 文本域初始化
        jQuery(document).ready(function(){

            $('.summernote').summernote({
                height: 300,                 // set editor height
                minHeight: null,             // set minimum height of editor
                maxHeight: null,             // set maximum height of editor
                focus: false ,                // set focus to editable area after initializing summernote

            });

            $('.inline-editor').summernote({
                airMode: true
            });


            $('.summernote').code('{{AssetsData.description}}');

            $('button[type=submit]').click(function(e) {
                e.preventDefault();
                var $this = $(this);

                if(!$this.hasClass('disabled')) {

                    var sHTML = $('.summernote').code();
                    if($('input[name=summernote]').length) {
                        $('input[name=summernote]').val(sHTML);
                    } else {
                        $('.form-horizontal').append('<input type="hidden" name="summernote" value="' + sHTML + '" />');
                    }

                    $.ajax({
                        method: 'POST',
                        dataType: 'json',
                        url: '{% url "ChangeAsset" AssetsData.id %}',
                        data: $('.form-horizontal').serialize(),
                        success: function(data) {
                            var msginfo = data.msginfo;
                            if(msginfo){
                              $.Notification.autoHideNotify('success','top right','系统通知', msginfo);
                              setTimeout(function() {
                                   location.href = '{% url 'AssetsLists'  1 %}';
                              },2500);
                            }else{

                            }
                        },
                        error: function() {},
                        complete: function() {
                            $this.removeClass('disabled');
                        }
                    })
                }
            });

        });


    });

</script>

{% endblock %}

